<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<div id="pagination">
    <%-- Lien précédent --%>
    <c:if test="${page != 1}">
        <a href="<c:url value="/ctrl/?action=cata&page=${page - 1}&nbres=${sessionScope.nbres}"/>"><-|</a>
    </c:if>
    <c:choose>
        <c:when test="${nbpages<=20}">
            <%--For displaying Page numbers.
            The when condition does not display a link for the current page--%>
            <c:forEach begin="1" end="${nbpages}" var="i">
                <c:choose>
                    <c:when test="${page eq i}">
                        - ${i} - 
                    </c:when>
                    <c:otherwise>
                        <a href="<c:url value="/ctrl/?action=cata&page=${i}&nbres=${sessionScope.nbres}"/>">${i}</a> 
                    </c:otherwise>
                </c:choose>
            </c:forEach>
        </c:when>
        <c:when test="${nbpages>20 && page < 20}">
            <c:forEach begin="1" end="${19}" var="i">
                <c:choose>
                    <c:when test="${page eq i}">
                        - ${i} - 
                    </c:when>
                    <c:otherwise>
                        <a href="<c:url value="/ctrl/?action=cata&page=${i}&nbres=${sessionScope.nbres}"/>">${i}</a> 
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            ...
        </c:when>         
        <c:otherwise>
            ...
            <c:forEach begin="20" end="${nbpages}" var="i">

                <c:choose>
                    <c:when test="${page eq i}">
                        - ${i} - 
                    </c:when>
                    <c:otherwise>
                        <a href="<c:url value="/ctrl/?action=cata&page=${i}&nbres=${sessionScope.nbres}"/>">${i}</a> 
                    </c:otherwise>
                </c:choose>
            </c:forEach>
        </c:otherwise>
    </c:choose>
    <%-- Lien suivant --%>
    <c:if test="${page lt nbpages}">
        <a href="<c:url value="/ctrl/?action=cata&page=${page + 1}&nbres=${sessionScope.nbres}"/>">|-></a>
    </c:if>

</div>